<html>
<head>
<title>Swing Data Bindings</title>
<meta content="text/html; charset=windows-1252" http-equiv="Content-Type">
<link href="../../../../book.css" rel="stylesheet" type="text/css">
</head>
<body bgcolor="#FFFFFF">
    <h1>Swing Data Bindings</h1>
	<h3>Supported for JDK 1.5 
	and above only</h3>
	<p class="pnoall">Click the
	<b>Bindings</b> tab in the editor to created and edit 
	data bindings.</p>
	<p class="pnoall">
	<img border="0" src="../../../wizards/swing/images/data_binding_tab.gif" align="absbottom"></p>
	<p class="pnoall">
	<img border="0" src="../../../wizards/swing/images/automatic_data_binding8.gif"></p>
	<p class="pnoall">Swing uses simple bindings between targets and models. </p>
	<h2>Target &amp; Model Types</h2>
	<p class="pnoall">Two types of targets and models are supported:</p>
	<ul>
		<li>
		<p class="pnoall"><b>
		<img border="0" src="images/data_binding_beans_button.gif" align="absbottom"> 
		Beans</b>: any field of the current compilation unit may be selected. 
		The filter field above the list can be used to filter the list of beans. 
		The
		<img border="0" src="images/clear_filter_button.gif" width="23" height="22" align="absbottom"> 
		clear button can be used to clear the filter and restore the full list.
		<b>Beans</b> are the primary data source for bindings (usually the 
		model). Any property of the <b>Bean</b> may be observed. Individual 
		beans may also be expanded to reveal their direct sub properties.<br>
		<br>
		<img border="0" src="images/model_beans.gif">&nbsp;&nbsp;&nbsp;
		<img border="0" src="images/model_beans_filtered.gif" align="top"><br>
&nbsp;</li>
		<li>
		<p class="pnoall"><b>
		<img border="0" src="images/data_binding_widgets_button.gif" width="23" height="22" align="absbottom"> 
		Widgets</b>: any widget in the current compilation unit may be selected. 
		If a widget is not a field, it will be converted to a field 
		automatically. The filter field above the list can be used to filter the 
		list of widgets. The
		<img border="0" src="images/clear_filter_button.gif" width="23" height="22" align="absbottom"> 
		clear button can be used to clear the filter and restore the full list. 
		Any property of the <b>Widget</b> may be observed.<br>
		<br>
		<img border="0" src="images/target_widgets.gif">&nbsp;&nbsp;&nbsp;&nbsp;
		<img border="0" src="images/target_widgets_filtered.gif" align="top"></li>
	</ul>
	<h2>Properties</h2>
	<p class="pnoall">When any <b>Target</b> or <b>Model</b> object is selected, 
	its properties (bean fields or standard Swing widget properties) are shown 
	in the associated <b>Properties</b> list. Properties may be expanded to show 
	their nested attributes. A drop down filter menu is 
	available to filter the Property list by type and hide or show the advanced 
	properties. Supported filters are <b>
	String</b>, <b>Boolean</b>, <b>Numbers</b>, <b>Color</b>, <b>Font </b>and <b>
	Image</b>.</p>
	<p class="pnoall">
	<img border="0" src="images/properties.gif" align="top">
	<img border="0" src="images/properties_expanded.gif" align="top" width="171" height="346">
	<img border="0" src="images/properties_filtered.gif" align="top">
	<img border="0" src="images/properties_advanced.gif" width="292" height="339">
	<img border="0" src="images/filter_button.gif" align="top"></p>
	<h2>New Swing Bindings</h2>
	<p class="pnoall">New bindings are created by selecting a <b>Target</b>, a
	<b>Target Property</b>, a <b>Source</b>, a <b>Source Property</b> and 
	clicking the
	<img border="0" src="images/binding_button.gif" width="26" height="24" align="absbottom">
	<b>Bind</b> button. When creating a binding, the update strategy from <b>
	target to model</b> and <b>model to target</b> may be specified as well as 
	any strategy-specific properties (converter and validator). </p>
	<p class="pnoall">
	<img border="0" src="images/bind_properties_swing1.gif" align="top"></p>
	<p class="pnoall">When the Target or Model is a Text widget and the text 
	property is selected, the triggering event may be specified as <b>Swing.Modify</b>,
	<b>Swing.FocusOut</b> or <b>Swing.NONE</b>.</p>
	<p class="pnoall">
	<img border="0" src="images/text_events.gif"></p>
	<p class="pnoall">Predefined update value strategies - <b>READ_ONCE</b>,
	<b>READ</b> and <b>READ_WRITE</b> - may be selected.</p>
	<p class="pnoall">
	<img border="0" src="images/update_value_strategy.gif" align="top"></p>
	<p class="pnoall">When binding to a <b>&lt;EL Expression&gt;</b>, a text field is 
	provided where the expression may be entered.</p>
	<p class="pnoall">
	<img border="0" src="images/bind_properties_swing2.gif" align="top"></p>
	<p class="pnoall">
	When binding a JList to a collection of model objects, the detail of the 
	model (what is shown in the list) can be specified.</p>
	<p class="pnoall">
	<img border="0" src="images/example4.gif"></p>
	<p class="pnoall">
	When binding a JTable to a collection of model objects, column bindings may 
	be added for each model object property.</p>
	<p class="pnoall">
		<img border="0" src="images/example8.gif" align="top"> <img border="0" src="images/example10.gif"></p>
	<h2>Existing Swing Bindings</h2>
	<p class="pnoall">At the top of the page, existing <b>Bound Properties</b> 
	are listed. The <b>Target</b> and <b>Model</b> are shown as well as the <b>
	Strategy</b> and the <b>Binding</b> variable name. </p>
	<p class="pnoall">
	<img border="0" src="images/bound_properties_swing.gif" width="558" height="115"></p>
	<p class="pnoall">Clicking the
	<img border="0" src="images/data_binding_edit_button.gif" align="absbottom">
	<b>Edit</b> button or <b>Edit</b> menu opens the <b>Edit Binding</b> dialog 
	where the update strategy, converter and validator may be modified.</p>
	<p class="pnoall">
	<img border="0" src="images/edit_binding_swing.gif" align="top"></p>
	<p class="pnoall">The
	<img border="0" src="images/data_binding_delete_button.gif" align="absbottom">
	<b>Delete</b> button or <b>Delete</b> menu is used to delete the selected 
	bound property while the
	<img border="0" src="images/data_binding_delete_all_button.gif" align="absbottom">
	<b>Delete All</b> button or <b>Delete All</b> menu is used to delete all of 
	the bound properties.</p>
	<p class="pnoall">The
	<img border="0" src="images/data_binding_move_up_button.gif" align="absbottom" width="23" height="20">
	<b>Move Up</b> and
	<img border="0" src="images/data_binding_move_down_button.gif" align="absbottom" width="23" height="20">
	<b>Move Down</b> buttons and menus are used to change the order of the 
	bindings while the
	<img border="0" src="images/data_binding_goto_definition_button.gif" align="absbottom" width="23" height="20">
	<b>Goto Definition</b> button and menu are used to jump to the generated 
	code for the binding.</p>
	<h2>
	Source</h2>
		<p class="pnoall">As bindings are created or edited on the Bindings tab, 
		the necessary data binding 
		code is generated which may then be seen in the <b>Source</b> view. An <b>initDataBindings()</b> 
		method is created, if it does not already exist and a call to that 
		method is added to the end of the widget creation process.</p>
	<p class="pnoall">Within the <b>initDataBindings()</b> method, any needed 
	bean properties are created followed by the creation of each binding.</p>
	<p class="pnoall">
	<img border="0" src="images/data_binding_source.gif"></p>
	<p class="pnoall"><i><b>Warning: </b>do not edit the <b>initDataBinding()</b> 
	method by hand (without carefully matching the code generation pattern used 
	by the tool) as it will be regenerated in its entirety any time 
	the tool 
	needs to add, remove or update a data binding.</i></p>
          </body>
</html>